<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        console.log("test");
        function check() {
           // alert("表单想提交")
            return checkusername() && checkpassword()
        }
        function checkusername() {
            var username=document.myform.uname.value;
            var untip =document.getElementById("unametip");
            untip.innerHTML= "√";
            if(username.length ==0){
                untip.innerHTML= "用户名不能为空" ;
                return false;
            }
            if(username.length < 4){
                untip.innerHTML= " 用户名不能 少于四位";
                return false;
            }
            return true;
        }

//        var phoneReg = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/;
//        var nameReg = /^[\u4E00-\u9FA5]{2,4}$/;
        function checkpassword() {
            var pwd=document.myform.upwd.value;
            var   reg =/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
            var uptip =document.getElementById("utip");
            uptip.innerHTML= "√";
            if(!reg.test(pwd)){
                uptip.innerHTML="密码必须包含大小写和数字,且不少于8位"
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<form action="" name="myform" onsubmit="return check()">
    <input type="text" name="uname" onblur="checkusername()" id="uname" placeholder="请输入用户名" />
    <div id="unametip" style="display: inline"></div>
    <br/>
    <input type="text" name="upwd" id="upwd" onblur="checkpassword()" />
    <div id="utip" style="display: inline"></div><br/>
    <input type="submit"/>
</form>
</body>
</html>